import Fighter from "../../resources/prefabs/Fighter";
import { SPINE_ACTION, FACE_DIR } from "../framework/utils/Define";
import Bullet from "../../resources/prefabs/Bullet";
import NodeUtil from "../framework/utils/NodeUtil";

/**
 * 战场
 */
const {ccclass, property} = cc._decorator;

@ccclass
export default class BattleView extends cc.Component {

    @property({type:cc.Node,tooltip:"敌人层"})
    EnemyLayer:cc.Node = null;
    @property({type:cc.Node,tooltip:"战机层"}) 
    FighterLayer:cc.Node = null;
    @property({type:cc.Node,tooltip:"子弹层"})  
    BulletLayer:cc.Node = null;
 
    /**
     *  加入战场
     * @param fighter 战机
     * @param pos  位置
     */
    addFighterLayer(fighter:cc.Node,pos:cc.Vec3){
        this.FighterLayer.addChild(fighter);
        fighter.position = pos;
        let fighterCom = fighter.getComponent(Fighter)
        fighterCom.playAni(SPINE_ACTION.ATTACK_FLY);
        fighterCom.setEnemy(this.EnemyLayer.getChildByName("enemy")) 
        fighterCom.getComponent(Fighter).startAI();
    }

    /**
     * 添加子弹进入战场
     */
    addBulletLayer(bullet:Bullet,v2:cc.Vec2){
        bullet.setParent(this.BulletLayer); 
        bullet.setPostion(v2.x,v2.y); 
        bullet.openFire(); 
    }


}
